<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <ui:composition template="../TemplateAdmin.xhtml">
        <ui:define name="title">
            <h:outputText value="Manager Management"></h:outputText>
        </ui:define>       
        <ui:define name="body">    
            <h:form id="form">
                <p:growl id="messages" showDetail="true"/> 
                <p:dataTable id="dataTable" var="item" value="#{managerController.items}" resizableColumns="true"
                             paginator="true" rows="10" paginatorPosition="bottom"
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             rowsPerPageTemplate="5,10,15" style="width: 100%" widgetVar="managerTable"
                             editable="true">
                    <f:facet name="header">
                        <h:outputText value="List of Manager"/>
                        <p:outputPanel style="float: right">
                            <h:outputText value="Search by all fileds"/>
                            <h:inputText id="globalFilter" onkeyup="managerTable.filter"/>
                        </p:outputPanel>
                    </f:facet>

                    <p:ajax event="rowEdit" listener="#{managerController.onEdit}" update=":form:messages"/>
                    <p:ajax event="rowEditCancel" listener="#{managerController.onEditCancel}" update=":form:messages"/>

                    <p:column headerText="ID" sortBy="#{item.mnID}">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.mnID}"/>
                            </f:facet>
                            <f:facet name="input">
                                <h:outputText value="#{item.mnID}" style="width: 100%"/>
                            </f:facet>
                        </p:cellEditor>                    
                    </p:column>
                    <p:column headerText="Name" sortBy="#{item.mnName}"
                              filterBy="#{item.mnName}" filterMatchMode="exact">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.mnName}"/>
                            </f:facet>
                            <f:facet name="input">
                                <h:inputText value="#{item.mnName}" style="width: 100%">
                                    <f:validateLength minimum="1" /> 
                                </h:inputText>
                            </f:facet>
                        </p:cellEditor>                    
                    </p:column>                
                    <p:column headerText="UserName" sortBy="#{item.mnUserName}"
                              filterBy="#{item.mnUserName}" filterMatchMode="exact">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.mnUserName}"/>
                            </f:facet>
                            <f:facet name="input">
                                <h:inputText value="#{item.mnUserName}" style="width: 100%">
                                    <f:validateLength minimum="1" maximum="10" />
                                </h:inputText>
                            </f:facet>
                        </p:cellEditor>                    
                    </p:column>

                    <p:column headerText="Email" sortBy="#{item.mnEmail}"
                              filterBy="#{item.mnEmail}" filterMatchMode="exact">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.mnEmail}"/>
                            </f:facet>
                            <f:facet name="input">
                                <h:inputText value="#{item.mnEmail}" style="width: 100%">
                                    <!-- <f:validateRegex pattern="^[a-zA-Z]" /> -->
                                </h:inputText>
                            </f:facet>
                        </p:cellEditor>                    
                    </p:column>
                    <p:column headerText="Phone" sortBy="#{item.mnPhone}"
                              filterBy="#{item.mnPhone}" filterMatchMode="exact">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.mnPhone}"/>
                            </f:facet>
                            <f:facet name="input">
                                <h:inputText value="#{item.mnPhone}" style="width: 100%">
                                    <!-- <f:validateRegex pattern="^[a-zA-Z]" /> -->
                                </h:inputText>
                            </f:facet>
                        </p:cellEditor>                    
                    </p:column>
                    <p:column headerText="Adress" sortBy="#{item.mnAdress}"
                              filterBy="#{item.mnAdress}" filterMatchMode="exact">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.mnAdress}"/>
                            </f:facet>
                            <f:facet name="input">
                                <h:inputText value="#{item.mnAdress}" style="width: 100%"/>
                            </f:facet>
                        </p:cellEditor>                    
                    </p:column>               

                    <p:column headerText="Status" sortBy="#{item.mnStatus}">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{item.mnStatus}"/>
                            </f:facet>
                            <f:facet name="input">
                                <h:selectBooleanCheckbox value="#{item.mnStatus}" />
                            </f:facet>
                        </p:cellEditor>                    
                    </p:column> 
                    <p:column sortBy="#{item.mnPermission}" headerText="Permission"
                              filterBy="#{item.mnPermission}" filterMatchMode="exact" >
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="Admin" rendered="#{item.mnPermission == 0}"/>  
                                <h:outputText value="Staff Order" rendered="#{item.mnPermission == 1}"/>  
                                <h:outputText value="Staff Project" rendered="#{item.mnPermission == 2}"/>                           
                            </f:facet>
                            <f:facet name="input">                         

                                <p:selectOneMenu value="#{item.mnPermission}" id="mnPermission" style="width: 100%">   
                                    <f:selectItem itemLabel="Select One" itemValue="" />
                                    <f:selectItem itemLabel="Admin" itemValue="0" />
                                    <f:selectItem itemLabel="Staff Order" itemValue="1" />  
                                    <f:selectItem itemLabel="Staff Project" itemValue="2" /> 

                                </p:selectOneMenu>
                            </f:facet>
                        </p:cellEditor> 
                    </p:column>
                    <p:column>
                        <p:rowEditor/>
                    </p:column>
                </p:dataTable>

            </h:form>
        </ui:define>
    </ui:composition>
</html>

